<template>
  <ga-pagination
    :total="total"
    v-model="currentPage"
    show-total
    size="mini"
    show-jumper
    @change="handleCurrentChange"
    @page-size-change="handleSizeChange"
    show-page-size
  />
</template>
<script  setup>
  import { computed, defineProps, defineEmits } from 'vue';

  const props = defineProps({
    total: {
      require: true,
      default: 88,
    },
    page: {
      require: true,
      default: 1,
    },
    limit: {
      require: true,
      default: 10,
    },
    pageSize: {
      type: Array,
      default() {
        return [10, 20, 30, 40];
      },
    },
  });
  const emit = defineEmits(['update:page', 'update:limit', 'pagination']);
  const currentPage = computed({
    get() {
      return props.page;
    },
    set(val) {
      emit('update:page', val);
    },
  });
  const pageSize = computed({
    get() {
      return props.limit;
    },
    set(val) {
      emit('update:limit', val);
    },
  });
  const handleSizeChange = (val) => {
    emit('pagination', { page: currentPage.value, limit: val });
  };
  const handleCurrentChange = (val) => {
    emit('pagination', { page: val, limit: pageSize.value });
  };
</script>
